*******************************************************************************
******************************  FIGURE 6  *************************************
***************  Simulated voting rates, by condition and  ********************
*********************  intensity of discrimination  ***************************
*******************************************************************************

//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/figure_6"

********************************************************************************
**Study 2 Analysis
*Pre-Leader 
use "figure_6_dataset.dta", clear
reg femvotesminfl_avgpre_ratio i.condition_2f, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupfemvotesminfl_avgpre_ratio.dta", replace dta side noparen noas

ttest femvotesminfl_avgpre_ratio if condition_2f==0 | condition_2f==1, by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupfemvotesminfl_avgpre_ratiop.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.3
putexcel save

use "intermediate_data/study2_newfig_groupfemvotesminfl_avgpre_ratio_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupfemvotesminfl_avgpre_ratio_forgraphing.csv", replace


*Post-Leader Male Leader
use "figure_6_dataset.dta", clear
reg femvotesminfl_avgpost_ratio i.condition_2f if fem_leader == 0, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_male.dta", replace dta side noparen noas

ttest femvotesminfl_avgpost_ratio if (fem_leader == 0) & (condition_2f==0 | condition_2f==1), by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_malep.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.3
putexcel save

use "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_male_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_male_forgraphing.csv", replace


*Post-Leader Female Leader
use "figure_6_dataset.dta", clear
reg femvotesminfl_avgpost_ratio i.condition_2f if fem_leader == 1, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_fem.dta", replace dta side noparen noas

ttest femvotesminfl_avgpost_ratio if (fem_leader == 1) & (condition_2f==0 | condition_2f==1), by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_femp.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.3
putexcel save

use "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_fem_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupfemvotesminfl_avgpost_ratio_fem_forgraphing.csv", replace














